/**
 *  This file is part of AugeasWH.
 *
 *  AugeasWH. is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AugeasWH. is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with AugeasWH.  If not, see <http://www.gnu.org/licenses/>.
 */

package cz.fit.vutbr.pis2012.augeaswh.persistence;

import java.io.Serializable;
import javax.persistence.*;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import static javax.persistence.CascadeType.ALL;


/**
 * The persistent class for the stock_items database table.
 * 
 */
@Entity
@Table(name="stock_items")
public class StockItem implements Serializable, AugeasWHEntity {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Column(name="delivery_date")
	private Timestamp deliveryDate;

	//bi-directional many-to-one association to SlotsStockItem
	@OneToMany(mappedBy="stockItem", cascade = ALL)
	private List<SlotsStockItem> slotsStockItems;

	//bi-directional many-to-one association to Subject
    @ManyToOne
	@JoinColumn(name = "subject_id", referencedColumnName = "id")
	private Supplier supplier;

	//bi-directional many-to-one association to StockType
    @ManyToOne
	@JoinColumn(name="stock_type_id")
	private StockType stockType;

    public StockItem() {
    }

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Timestamp getDeliveryDate() {
		return this.deliveryDate;
	}

	public void setDeliveryDate(Timestamp deliveryDate) {
		this.deliveryDate = deliveryDate;
	}

	public List<SlotsStockItem> getSlotsStockItems() {
		return this.slotsStockItems;
	}

	public void setSlotsStockItems(List<SlotsStockItem> slotsStockItems) {
		this.slotsStockItems = slotsStockItems;
	}
	
	public Supplier getSupplier() {
		return this.supplier;
	}

	public void setSupplier(Supplier supplier) {
		this.supplier = supplier;
	}
	
	public StockType getStockType() {
		return this.stockType;
	}

	public void setStockType(StockType stockType) {
		this.stockType = stockType;
	}
	
	public void addSlotStockItem(SlotsStockItem item) {
		if (item == null) 
			return;
		if (slotsStockItems == null)
			slotsStockItems = new ArrayList<SlotsStockItem>();
		slotsStockItems.add(item);
		
	}
	
	public void removeSlotStockItem(SlotsStockItem item) {
		if (item == null || slotsStockItems == null)
			return;
		slotsStockItems.remove(item);
	}
	
}